<?php

namespace App\Repositories;

use App\Models\BarCode;
use Cache;
class BarCodeRepository extends Repository
{
    static $tag = 'testing.barCode';


    public function getById($id)
    {
        $cacheKey = getCacheKey('testing.barCode.info') . $id;
        $value = $this->remember($cacheKey, function () use ($id) {
            return BarCode::where('id', $id)->first();
        });
        return $value;
    }

    public function getByBarCode($barCode)
    {
        $cacheKey = getCacheKey('testing.barCodes.info').$barCode;
        $this->clearCache('testing.barCodes.info');
        $value = $this->remember($cacheKey, function () use ($barCode) {
            return BarCode::where('bar_code_id', $barCode)->first();
        });
        return $value;
    }


     public function store($data)
     {
        $this->clearCache($this->tag());
        $res = BarCode::firstOrCreate($data);
        return $res;
     }



    public function cacheTime()
    {
        return config('testing.common_cache_time');
    }


    public function model()
    {
        return app(BarCode::class);
    }

    public function tag()
    {
        return self::$tag;
    }
}